:root {
    --primary-bg: #343541;
    --secondary-bg: #202123;
    --accent-color: #2196f3;
    --text-color: #ececf1;
    --border-color: rgba(255, 255, 255, 0.1);
    --sidebar-width: 260px;
    --transition-time: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif;
    height: 100vh;
    color: var(--text-color);
    background: var(--primary-bg);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--secondary-bg);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-time) ease;
    position: fixed;
    height: 100vh;
    border-right: 1px solid var(--border-color);
    z-index: 100;
    left: 0;
    top: 0;
}

.sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 10px;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition-time) ease;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-item.active {
    background: rgba(255, 255, 255, 0.1);
}

.chat-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

.new-chat-btn,
.toggle-sidebar-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    cursor: pointer;
}

.toggle-sidebar-btn {
    margin-left: auto;
}

.download-btn,
.delete-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-time) ease;
}

.chat-item:hover .download-btn,
.chat-item:hover .delete-btn {
    opacity: 1;
}

.sidebar-toggle-container {
    position: fixed;
    top: 10px;
    left: 0;
    z-index: 99;
    transition: all var(--transition-time) ease;
}

.restore-sidebar-btn {
    width: 24px;
    height: 32px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-left: none;
    color: var(--text-color);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 0 6px 6px 0;
}

.sidebar.hidden ~ .sidebar-toggle-container .restore-sidebar-btn {
    display: flex;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    transition: padding-left var(--transition-time) ease, width var(--transition-time) ease;
    width: 100%;
    position: relative;
}

.sidebar:not(.hidden) ~ .main-content {
    padding-left: var(--sidebar-width);
    width: 100%;
}

.sidebar.hidden ~ .main-content {
    padding-left: 0;
    width: 100%;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    max-width: 800px;
    padding: 20px;
    margin: 0 auto;
}

.welcome-screen h1 {
    font-size: 2em;
    margin-bottom: 20px;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    padding: 20px 0;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
}

.message-wrapper {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    gap: 12px;
}

.message.user .message-wrapper {
    justify-content: flex-end;
}

.message-content {
    max-width: 80%;
    background: rgba(255, 255, 255, 0.1);
    padding: 12px 16px;
    border-radius: 8px;
    line-height: 1.6;
    font-size: 14px;
}

.message.user .message-content {
    background: var(--accent-color);
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.1);
}

.message.user .message-avatar {
    order: 1;
    background: var(--accent-color);
}

.input-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    background: var(--primary-bg);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.message-input {
    width: 100%;
    padding: 12px 40px 12px 15px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    resize: none;
    min-height: 52px;
    max-height: 200px;
    font-size: 14px;
    line-height: 1.5;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.send-button {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
}

.send-button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 24px;
    background: rgba(0,0,0,0.8);
    color: white;
    border-radius: 4px;
    z-index: 1000;
}

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100vh;
    }

    .sidebar:not(.hidden) ~ .main-content {
        padding-left: 0;
    }

    .main-content {
        width: 100%;
    }

    .welcome-screen,
    .chat-container,
    .input-container {
        padding: 20px 10px;
    }

    .sidebar-toggle-container {
        display: none;
    }
}

/* 模型选择器定位规则 */
/* 当侧边栏隐藏时（和之前一样），放在左上角 */
.sidebar.hidden ~ .main-content .model-selector-container {
    position: absolute;
    top: 10px;
    left: 20px;
    z-index: 10;
}

/* 当侧边栏显示时，将下拉栏右移，以避开侧边栏 */
.sidebar:not(.hidden) ~ .main-content .model-selector-container {
    position: absolute;
    top: 10px;
    left: calc(var(--sidebar-width) + 20px);
    z-index: 10;
}

.model-selector-container select {
    background: rgba(255,255,255,0.1);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
}
